import { customForm } from "@/components/ProForm/interface/index";
import { User } from "@/api/interface";
import { ProTableValue } from "@/interface/public";

import { defaultStyle } from "@/basic/style";

export function useAddForm(proTableBox: ProTableValue) {
  let addForm = reactive<customForm<User.ResUserList>>({
    form: {},
    title: "",
    visible: false,
    options: [
      {
        label: "id",
        prop: "id",
        hide: true,
        type: "input",
        defaultValue: ""
      },
      {
        type: "input",
        label: "username",
        hide: false,
        prop: "username",
        defaultValue: "",
        rules: [{ required: true, message: "Please input Activity name", trigger: "blur" }]
      },
      {
        type: "input",
        label: "name",
        hide: false,
        defaultValue: "",
        prop: "name"
      },
      {
        type: "input",
        label: "remark",
        defaultValue: "",
        hide: false,
        prop: "remark",
        attrs: {
          style: defaultStyle
        }
      }
    ]
  });

  const saveAddForm = async (form: User.ResUserList) => {
    console.log(form, "form");

    await userSave(form);
    addForm.visible = false;

    proTableBox.value?.getTableList();
  };

  return { addForm, saveAddForm };
}
